import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<Integer> partitionLabels(String s) {
        int[] last = new int[26];
        int n = s.length();
        for(int i = 0; i < n; i++){
            last[s.charAt(i) - 'a'] = i;
        }
        int left = 0, right = last[s.charAt(0) - 'a'], ret = 0;
        List<Integer> list = new ArrayList<>();
        while(true){
            if(left == right){
                list.add(left - ret + 1);
                ret = left + 1;
                if(left == n-1){
                    return list;
                }
            }
            left++;
            right = Math.max(right, last[s.charAt(left) - 'a']);
        }

    }
}
